package com.zhihu_lvliangi_android.service.volley;

import java.util.HashMap;
import java.util.Map;

import com.android.volley.AuthFailureError;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.StringRequest;
import com.zhihu_lvliangi_android.service.ClientTask;
import com.zhihu_lvliangi_android.service.MobileApplication;

/**
 *
 *
 * @author azuryleaves
 * @since 2014-8-28 上午9:54:12
 * @version 1.0
 *
 */
public class StringRequestPut extends StringRequest {

	private Map<String, String> params;  
	
	public StringRequestPut(int method, String url, Listener<String> listener, ErrorListener errorListener) {
		super(method, url, listener, errorListener);
	}

	public StringRequestPut(String url, Map<String, String> params, Listener<String> listener, ErrorListener errorListener) {
		this(Method.PUT, url, listener, errorListener);
		this.params = params;
	}

	@Override
	protected Map<String, String> getParams() throws AuthFailureError {
		return params;
	}
	
	@Override
	public Map<String, String> getHeaders() throws AuthFailureError {
		String cookies = MobileApplication.preferences.getString(ClientTask.COOKIES, null);
		if (cookies != null && cookies.length() > 0) {
			HashMap<String, String> headers = new HashMap<String, String>();
			headers.put("Cookie", cookies);
			return headers;
		}
		return super.getHeaders();
	}
	
}
